package com.qk.mangement.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.role.RoleDTo;
import com.qk.entity.Role;
import com.qk.mangement.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Date:2025/10/9
 * Author:zxc
 * Description
 */
@Slf4j
@RestController
@RequestMapping("/roles")
public class RoleController {

    @Autowired
    private RoleService roleService;


    //创建分页查询
    @GetMapping
    public Result queryListByPage(RoleDTo roleDTO) {
        log.info("分页查询参数：{}", roleDTO);
        PageResult<Role> queryListByPageVO = roleService.queryListByPage(roleDTO);
        return Result.success(queryListByPageVO);
    }


    @DeleteMapping("/{id}")
    public Result deleteById(Integer id) {
        log.info("删除角色，id：{}", id);
        roleService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Role role) {
        log.info("添加角色：{}", role);
        roleService.addUser(role);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id) {
        log.info("查询角色，id：{}", id);
        return Result.success(roleService.getById(id));
    }

    @PutMapping
    public Result update(@RequestBody Role role) {
        log.info("修改角色：{}", role);
        roleService.update(role);
        return Result.success();
    }

    //创建查询
    @RequestMapping("/list")
    public Result queryAll() {
        log.info("查询所有角色");
        return Result.success(roleService.queryAll());
    }
}

